# Definition for singly-linked list.
from typing import Optional


class ListNode:

    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution:

    def reorderList(self, head: Optional[ListNode]) -> None:
        """
        Do not return anything, modify head in-place instead.
        """
        a = []
        while head is not None:
            a.append(head)
            head = head.next
        l, r = 0, len(a) - 1
        ans = node = ListNode()
        while l <= r:
            if l < r:
                node.next = a[l]
                node = node.next
                node.next = a[r]
            else:
                node.next = a[l]
            node = node.next
            l += 1
            r -= 1
        node.next = None
        return ans.next